﻿<UserControl x:Name="RouteFinder" x:Class="Tanis.Controls.RouteFinderControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:system="clr-namespace:System;assembly=mscorlib"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    d:DesignHeight="541" d:DesignWidth="450" 
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:localControls="clr-namespace:Tanis.Controls">

    <UserControl.Resources>
        <localControls:AutoCompleteVisibilityConverter x:Key="Vis"/>
        <ControlTemplate x:Key="AutoCompleteBoxControlTemplateDefault" TargetType="toolkit:AutoCompleteBox">
			<Grid>
				<Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <TextBox
                        KeyDown="OnAutoCompleteBox_KeyDown"
                        x:Name="Text"
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        FontFamily="{TemplateBinding FontFamily}"
                        FontSize="25"
                        FontStyle="{TemplateBinding FontStyle}"
                        FontWeight="{TemplateBinding FontWeight}"
                        Foreground="{TemplateBinding Foreground}"
                        InputScope="{TemplateBinding InputScope}"
                        Opacity="{TemplateBinding Opacity}"
                        Padding="{TemplateBinding Padding}"
                        Style="{TemplateBinding TextBoxStyle}"/>
                <ListBox
                        Margin="3"
                        Visibility="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource Vis}}"
                        Grid.Row="1"
                        x:Name="Selector"
                        Background="DarkGray"
                        FontFamily="{TemplateBinding FontFamily}"
                        FontSize="25"
                        FontStyle="{TemplateBinding FontStyle}"
                        FontWeight="{TemplateBinding FontWeight}"
                        Foreground="{TemplateBinding Foreground}"
                        IsTabStop="False"
                        ItemContainerStyle="{TemplateBinding ItemContainerStyle}"
                        ItemTemplate="{TemplateBinding ItemTemplate}"
                        Opacity="{TemplateBinding Opacity}"
                        BorderBrush="{StaticResource PhoneTextBoxEditBorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        Padding="0,8"/>
            </Grid>
        </ControlTemplate>
        <DataTemplate x:Key="AutoCompleteItemDataTemplateDefault">
        	<TextBlock Text="{Binding}" TextWrapping="Wrap" Style="{StaticResource PhoneTextLargeStyle}"/>
        </DataTemplate>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" >
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>            
        </Grid.RowDefinitions>
        <TextBlock Grid.Row="0" Text="{Binding Path=LocalizedResources.StartStationOrAddress, Source={StaticResource LocalizedStrings}}" FontSize="18" Tag="departure"/>
        <toolkit:AutoCompleteBox
                Grid.Row="1"
                MinimumPrefixLength="3"
                ValueMemberBinding="{Binding}"
                FilterMode="Custom"
                x:Name="_startTextBox"
                InputScope="Default"
                SelectionChanged="OnAutoCompleteBox_SelectionChanged"
                Populating="autoCompleteBox_Populating"
                GotFocus="OnAutoCompleteBox_GotFocus"
                LostFocus="OnAutoCompleteBox_LostFocus"
				Template="{StaticResource AutoCompleteBoxControlTemplateDefault}"
				ItemTemplate="{StaticResource AutoCompleteItemDataTemplateDefault}"
                Tag="departure" />
        <TextBlock Grid.Row="3" Text="{Binding Path=LocalizedResources.DestinationStationOrAddress, Source={StaticResource LocalizedStrings}}" FontSize="18" Tag="arrival"/>
        <toolkit:AutoCompleteBox
                Grid.Row="4"
                MinimumPrefixLength="3"
                ValueMemberBinding="{Binding}"
                FilterMode="Custom"
                x:Name="_destTextBox"
                InputScope="Default"
                Populating="autoCompleteBox_Populating"
                GotFocus="OnAutoCompleteBox_GotFocus"
                LostFocus="OnAutoCompleteBox_LostFocus"
                SelectionChanged="OnAutoCompleteBox_SelectionChanged"
				Template="{StaticResource AutoCompleteBoxControlTemplateDefault}"
				ItemTemplate="{StaticResource AutoCompleteItemDataTemplateDefault}"
                Tag="arrival">
        </toolkit:AutoCompleteBox>
        <StackPanel Grid.Row="6" Orientation="Horizontal">
            <TextBlock FontSize="18" Name="_departureSelected" Text="{Binding Path=LocalizedResources.DepartTime, Source={StaticResource LocalizedStrings}}" Tap="_departureSelected_Tap"/>
            <TextBlock FontSize="18" HorizontalAlignment="Center" Text="/" Padding="10,0"/>
            <TextBlock FontSize="18" Name="_arrivalSelected" Text="{Binding Path=LocalizedResources.ArrivalTime, Source={StaticResource LocalizedStrings}}" Tap="_arrivalSelected_Tap" TextDecorations="Underline" Foreground="#DE2D50C5"/>
        </StackPanel>
        <StackPanel Grid.Row="7" Orientation="Horizontal">
            <toolkit:DatePicker  Name="_dateCtrl" Height="72" Width="178" FontSize="8" />
            <toolkit:TimePicker Name="_timeCtrl" />
        </StackPanel>
        <TextBlock Grid.Row="2" Name="validStart" Text="{Binding Path=LocalizedResources.StartAddressValidator, Source={StaticResource LocalizedStrings}}" VerticalAlignment="Top" Foreground="Red" Visibility="Collapsed" Tag="validator"/>
        <TextBlock Grid.Row="5" Name="validDest" Text="{Binding Path=LocalizedResources.DestinationAddressValidator, Source={StaticResource LocalizedStrings}}" VerticalAlignment="Top" Foreground="Red" Visibility="Collapsed" Tag="validator"/>
    </Grid>
</UserControl>
